/* TABS WITH MEMORY BY DAVE REEDER */
(function($){
	memoryTabs = function() {
// ASSIGN A VARIABLE TO COOKIES VALUE
		var currentIndex = $.cookie("tabsMemory");
		
		// SET CURRENT TAB AND CURRENT PANELS
		if (currentIndex > 0) {
				var currentTab = $('.tabNavigation a').eq(currentIndex-1);		
				var currentPanel = $('.tabContainer div').eq(currentIndex-1);
			}
		else {
				var currentTab = $('.tabNavigation a:first');
				var currentPanel = $('.tabContainer div:first'); 
			}
		
		// SET CLASS TO MAKE CURRENT TAB STYLED CORRECTLY
		currentTab.addClass("currentTab");
		
		// HIDE ALL CONTENT PANELS, SHOW CURRENT TAB CONTENT PANEL
		$('.tabContainer > div').fadeTo(0, 0); // FADE ALL TABS TO 0
		currentPanel.css("display", "block").fadeTo(0, 1); // SHOW CURRENT TAB
		
		// CLICK EVEN FOR EACH TAB IN NAV
		$('.tabNavigation a').each(            
                function( intIndex ){           // FOR EACH ELEMENT RUN THIS FUNCTION intIndex IS THE LOOP ITERATION INDEX
                    $(this).click(function(event) {
                        $('.tabContainer > div').fadeTo(0, 0).css("display", "none");  /* fade all others out and then hide them */
                        $('.tabContainer > div').eq(intIndex).css("display", "block").fadeTo(300, 1); /* fade in required div */
						$('.tabNavigation a').removeClass();
						$(this).addClass('currentTab');
						// SET COOKIE
						var cookieValue = $(this).attr('rel');
						//alert(cookieValue);
						$.cookie("tabsMemory", cookieValue, { expires: 7 });
                    });
                }
            );

};
})(jQuery);
